//
//  YQRegistViewController.m
//  EPA--1
//
//  Created by lanou3g on 16/4/27.
//  Copyright © 2016年 刘永庆. All rights reserved.
//

#import "YQRegistViewController.h"

@interface YQRegistViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailField;
@property (weak, nonatomic) IBOutlet UITextField *userNameField;
@property (weak, nonatomic) IBOutlet UITextField *passWorldField;

@end

@implementation YQRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (IBAction)didClickRegistAction:(UIButton *)sender {
    [YQNetWorkRequestManager requestURL:[NSURL URLWithString:@"http://api2.pianke.me/user/reg"] method:YQ_POST params:@{@"email":[NSString stringWithFormat:@"%@@126.com",self.emailField.text],@"gender":@0,@"uname":self.userNameField.text,@"passwd":self.passWorldField.text,} result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//             NSLog(@"%@",jsonDict);
            NSDictionary *dataDict = jsonDict[@"data"];
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:dataDict[@"msg"] ? dataDict[@"msg"] : @"成功" preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if ([jsonDict[@"result"] isEqual:@1]) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                         [self.navigationController popToRootViewControllerAnimated:YES];
                    });
                   
                }
                
            }]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
